﻿'/*
' * Copyright ¸ 2005 Kele (fooleau@gmail.com)
' * This library is free software you can redistribute it and/or 
' * modify it under the terms of the GNU Lesser General Public 
' * License version 2.1 as published by the Free Software Foundation
' * (the "LGPL").
' * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
' * OF ANY KIND, either express or implied.
' */
Imports System
Imports System.Text
Imports System.Security.Cryptography

Namespace Foole.Crypt
    '/ <summary>
    '/ A wrapper for .NET's SHA1 class
    '/ This is designed to be compatable with my initial implementation
    '/ </summary>
    Public Class Sha1Hash
        Private mSha As SHA1
        Private ZeroArray As Byte()

        Public Sub New()
            mSha = SHA1.Create()
        End Sub

        Public Sub Update(ByVal Data As Byte())
            mSha.TransformBlock(Data, 0, Data.Length, Data, 0)
        End Sub

        Public Sub Update(ByVal s As String)
            Update(Encoding.Default.GetBytes(s))
        End Sub

        Public Sub Update(ByVal Data As Int32)
            Update(BitConverter.GetBytes(Data))
        End Sub

        Public Sub Update(ByVal Data As UInt32)
            Update(BitConverter.GetBytes(Data))
        End Sub

        Public Function Final() As Byte()
            mSha.TransformFinalBlock(ZeroArray, 0, 0)
            Return mSha.Hash
        End Function

        Public Function Final(ByVal Data As Byte()) As Byte()
            mSha.TransformFinalBlock(Data, 0, Data.Length)
            Return mSha.Hash
        End Function

    End Class
End Namespace
